package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.generator.entity.AnnouncementEntity;
import io.renren.modules.generator.service.AnnouncementService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-04-05 21:39:15
 */
@RestController
@RequestMapping("generator/announcement")
@Api("公告列表")
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;

    /**
     * 列表
     */
    @ApiOperation("公告列表")
    @GetMapping("/list")
    @RequiresPermissions("generator:announcement:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = announcementService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("公告详情")
    @GetMapping("/info/{id}")
    @RequiresPermissions("generator:announcement:info")
    public R info(@PathVariable("id") Integer id){
		AnnouncementEntity announcement = announcementService.getById(id);

        return R.ok().put("announcement", announcement);
    }

    /**
     * 保存
     */
    @ApiOperation("保存公告（可以不使用）")
    @PostMapping("/save")
    @RequiresPermissions("generator:announcement:save")
    public R save(@RequestBody AnnouncementEntity announcement){
		announcementService.save(announcement);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改公告")
    @PostMapping("/update")
    @RequiresPermissions("generator:announcement:update")
    public R update(@RequestBody AnnouncementEntity announcement){
		announcementService.updateById(announcement);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除公告")
    @PostMapping("/delete")
    @RequiresPermissions("generator:announcement:delete")
    public R delete(@RequestBody Integer[] ids){
		announcementService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
